﻿using System;

namespace Library.OrmEnterpriseEntity.TableInfo {
	///<summary>
	///</summary>
	public class Int64Column : Column<Int64>, IConvertible {
		///<summary>
		///</summary>
		///<param name="metadata"></param>
		///<param name="table"></param>
		public Int64Column(DbColumnView metadata, DbTable table)
			: base(metadata, table) {
		}
		public override string ToString(string format, IFormatProvider formatProvider) {
			return Value.ToString(format, formatProvider);
		}
		///<summary>
		///</summary>
		///<param name="value"></param>
		///<returns></returns>
		public static implicit operator Int64Column(long value) {
			return new Int64Column(Int64ColumnView.Null, DbTable.Null) { Value = value };
		}
		///<summary>
		///</summary>
		public const Int64 DefaultInt64 = 0;
		internal static readonly Type Int64ColumnType = typeof(Int64Column);


		protected override long Default {
			get { return DefaultInt64; }
		}


		//public override DbType DbType {
		//  get { return DbType.Int64; }
		//}

		protected override long ConvertFrom(object value) {
			return Convert.ToInt64(value);
		}

		protected override bool Equal(long t1, long t2) {
			return t1 == t2;
		}

		#region Implementation of IConvertible

		TypeCode IConvertible.GetTypeCode() {
			return ((IConvertible)Value).GetTypeCode();
		}

		bool IConvertible.ToBoolean(IFormatProvider provider) {
			return ((IConvertible)Value).ToBoolean(provider);
		}

		char IConvertible.ToChar(IFormatProvider provider) {
			return ((IConvertible)Value).ToChar(provider);
		}

		sbyte IConvertible.ToSByte(IFormatProvider provider) {
			return ((IConvertible)Value).ToSByte(provider);
		}

		byte IConvertible.ToByte(IFormatProvider provider) {
			return ((IConvertible)Value).ToByte(provider);
		}

		short IConvertible.ToInt16(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt16(provider);
		}

		ushort IConvertible.ToUInt16(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt16(provider);
		}

		int IConvertible.ToInt32(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt32(provider);
		}

		uint IConvertible.ToUInt32(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt32(provider);
		}

		long IConvertible.ToInt64(IFormatProvider provider) {
			return ((IConvertible)Value).ToInt64(provider);
		}

		ulong IConvertible.ToUInt64(IFormatProvider provider) {
			return ((IConvertible)Value).ToUInt64(provider);
		}

		float IConvertible.ToSingle(IFormatProvider provider) {
			return ((IConvertible)Value).ToSingle(provider);
		}

		double IConvertible.ToDouble(IFormatProvider provider) {
			return ((IConvertible)Value).ToDouble(provider);
		}

		decimal IConvertible.ToDecimal(IFormatProvider provider) {
			return ((IConvertible)Value).ToDecimal(provider);
		}

		DateTime IConvertible.ToDateTime(IFormatProvider provider) {
			return ((IConvertible)Value).ToDateTime(provider);
		}

		string IConvertible.ToString(IFormatProvider provider) {
			return ((IConvertible)Value).ToString(provider);
		}

		object IConvertible.ToType(Type conversionType, IFormatProvider provider) {
			return ((IConvertible)Value).ToType(conversionType, provider);
		}

		#endregion
	}
}
